package org.sanelli.SaveTheShip.Function;

import java.util.ArrayList;

import org.sanelli.InterstellarGolf.GenericObject.*;
import org.sanelli.InterstellarGolf.SpecificObject.GameNPC;
import org.sanelli.InterstellarGolf.SpecificObject.GamePlayer;

public class PhysicFunction {
	private static double _Big_G = 6.67384E-11;
	
	public static double getG() {
		return _Big_G;
	}
	
	public static Vector2D gravity_acceleration_2d(GamePlayer player, GameNPC other) {
		Vector2D distance = Vector2D.sub(player.getPosition(), other.getPosition());
		double temp = distance.magnitude();
		temp = Math.pow(temp, 3);
		double acceleration = _Big_G * other.getMass();
		acceleration /= temp;
		/*The formula is F=-GMm / r^2*/
		return new Vector2D( -1 * acceleration * distance.getX(), -1 * acceleration * distance.getY() );
	}
	
	public static Vector2D total_acceleration(GamePlayer player, ArrayList<GameNPC> gamenpc) {
		Vector2D result = new Vector2D();
		for (GameNPC npc : gamenpc) {
			result.add(gravity_acceleration_2d(player, npc));
		}
		return result;
	}
}
